package com.kmproject.haifu.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DataHelper;
import com.jess.arms.widget.CustomPopupWindow;
import com.jess.arms.widget.autolayout.AutoToolbar;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.AppConstant;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.app.utils.StringUtils;
import com.kmproject.haifu.di.component.DaggerHousePublishOfficePublishComponent;
import com.kmproject.haifu.mvp.contract.HousePublishOfficePublishContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.MessageEvent;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberCenterUserInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoryBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserBean;
import com.kmproject.haifu.mvp.model.entity.resbean.HousePublicBean;
import com.kmproject.haifu.mvp.model.entity.resbean.ImgBean;
import com.kmproject.haifu.mvp.model.entity.resbean.SelectAddressMapBean;
import com.kmproject.haifu.mvp.presenter.HousePublishDuanZuPublishPresenter;
import com.kmproject.haifu.mvp.presenter.HousePublishOfficePublishPresenter;
import com.kmproject.haifu.mvp.ui.widget.MultiSelectPopWindow;
import com.kmproject.haifu.mvp.ui.widget.MultiSelectPopWindow1;
import com.suke.widget.SwitchButton;
import com.xw.repo.XEditText;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 08/07/2019 15:28
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class HousePublishOfficePublishActivity extends BaseActivity<HousePublishOfficePublishPresenter> implements HousePublishOfficePublishContract.View {

    @BindView(R.id.toolbar_backImg)
    ImageView toolbarBackImg;
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.back_right_icon)
    ImageView backRightIcon;
    @BindView(R.id.back_right_txt)
    TextView backRightTxt;
    @BindView(R.id.toolbar_right)
    RelativeLayout toolbarRight;
    @BindView(R.id.toolbar)
    AutoToolbar toolbar;
    @BindView(R.id.housepublishpublish_conten_img)
    ImageView housepublishpublishContenImg;
    @BindView(R.id.housepublishpublish_conten_camer_img)
    ImageView housepublishpublishContenCamerImg;
    @BindView(R.id.housepublishpublish_conten_noImg_lay)
    LinearLayout housepublishpublishContenNoImgLay;
    @BindView(R.id.housepublishpublish_conten_bt_txt)
    XEditText housepublishpublishContenBtTxt;
    @BindView(R.id.housepublishpublish_conten_szqy_txt)
    TextView housepublishpublishContenSzqyTxt;
    @BindView(R.id.housepublishpublish_conten_xxdz_txt)
    EditText housepublishpublishContenXxdzTxt;
    @BindView(R.id.housepublishpublish_conten_mj_txt)
    XEditText housepublishpublishContenMjTxt;
    @BindView(R.id.housepublishpublish_conten_lx_view)
    View housepublishpublishContenLxView;
    @BindView(R.id.housepublishpublish_conten_fwlx_txt)
    TextView housepublishpublishContenFwlxTxt;
    @BindView(R.id.housepublishpublish_conten_fwlx_lay)
    LinearLayout housepublishpublishContenLxLay;
    @BindView(R.id.housepublishpublish_conten_zx_txt)
    TextView housepublishpublishContenZxTxt;
    @BindView(R.id.housepublishpublish_conten_zx_lay)
    LinearLayout housepublishpublishContenZxLay;
    @BindView(R.id.housepublishpublish_conten_lc_txt)
    TextView housepublishpublishContenLcTxt;
    @BindView(R.id.housepublishpublish_conten_krngw_txt)
    TextView housepublishpublishContenKrngwTxt;
    @BindView(R.id.switch_button_sfkfg)
    SwitchButton switchButtonSfkfg;
    @BindView(R.id.switch_button_sfdbgjj)
    SwitchButton switchButtonSfdbgjj;
    @BindView(R.id.housepublishpublish_conten_zj_title_txt)
    TextView housepublishpublishContenZjTitleTxt;
    @BindView(R.id.housepublishpublish_conten_zj_txt)
    TextView housepublishpublishContenZjTxt;
    @BindView(R.id.housepublishpublish_conten_fkfs_view)
    View housepublishpublishContenFkfsView;
    @BindView(R.id.housepublishpublish_conten_fkfs_title_txt)
    TextView housepublishpublishContenFkfsTitleTxt;
    @BindView(R.id.housepublishpublish_conten_fkfs_txt)
    TextView housepublishpublishContenFkfsTxt;
    @BindView(R.id.housepublishpublish_conten_fkfs_lay)
    LinearLayout housepublishpublishContenFkfsLay;
    @BindView(R.id.housepublishpublish_conten_yj_txt)
    TextView housepublishpublishContenYjTxt;
    @BindView(R.id.housepublishpublish_conten_gsdp_txt)
    TextView housepublishpublishContenGsdpTxt;
    @BindView(R.id.housepublishpublish_gsdp_lay)
    LinearLayout housepublishpublishGsdpLay;
    @BindView(R.id.housePublisInfo_edit)
    EditText housePublisInfoEdit;
    @BindView(R.id.housePublisInfo_txt_num)
    TextView housePublisInfoTxtNum;
    @BindView(R.id.housepublishpublish_conten_lxr_txt)
    EditText housepublishpublishContenLxrTxt;
    @BindView(R.id.housepublishpublish_conten_man_txt)
    TextView housepublishpublishContenManTxt;
    @BindView(R.id.housepublishpublish_conten_woman_txt)
    TextView housepublishpublishContenWomanTxt;
    @BindView(R.id.Mystory_addStory_PhoneSsqy_txt)
    TextView MystoryAddStoryPhoneSsqyTxt;
    @BindView(R.id.Mystory_addStory_lxdh)
    EditText MystoryAddStoryLxdh;
    @BindView(R.id.housepublishpublish_conten_wxh_txt)
    EditText housepublishpublishContenWxhTxt;
    @BindView(R.id.HousePublishOfficePublish_sure_txt)
    TextView HousePublishOfficePublishSureTxt;
    @BindView(R.id.HousePublishOfficePublish_sure_lay)
    LinearLayout HousePublishOfficePublishSureLay;

    HousePublicBean housePublicBean = new HousePublicBean();
    List<MyStoryBean.ResultBean> mresultBeans;
    MyStoryBean.ResultBean selectResultBean;
    @BindView(R.id.housepublishpublish_conten_fgrnjj_lay)
    LinearLayout housepublishpublishContenFgrnjjLay;
    private List<ImgBean> imgBeans = new ArrayList<>();//上传图片地址封装
    private List<HousePayWayBean> houseyj;//押金getHouseArea
    private List<HousePayWayBean> housezx;//房屋装修

    private List<HousePayWayBean> housezfwlx;//房屋类型
    private List<HousePayWayBean> duanZuLx;//短租类型
    private int selectIndexfwlx, selectIndexLCDQ, selectIndexLCZS, selectIndexZX=-1, selectIndexYj, selectIndexZf, selectIndexLx;
    HousePayWayBean housePayWayBean;//发布类型，上一个页面传过来的
    private String sex = "男";
    private List<HousePayWayBean> houseArea;//区域
    private HousePayWayBean selectArea;//选中的区域
    private List<HousePayWayBean> mhousePayWayBeans;//支付方式
    private HousePayWayBean mfloor, mtoFloor, mtotalFloor;//当前楼层/到几层/总楼层
    private List<HousePayWayBean> mfloors;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerHousePublishOfficePublishComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_house_publish_office_publish; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public String reSetTitle() {
        if ("bgs".equals(housePayWayBean.getCategory())) {
            return ArmsUtils.getString(this, R.string.housepublishpublish_title_bgs);
        } else if ("cw".equals(housePayWayBean.getCategory())) {
            return ArmsUtils.getString(this, R.string.housepublishpublish_title_cw);
        } else {
            return ArmsUtils.getString(this, R.string.housepublishpublish_title_cfck);
        }
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
//        housepublishpublishContenXxdzTxt.setText("测试机");
//        housePublicBean.setAddressDetail("测试机哦");
//        housePublicBean.setLgt("102.045");
//        housePublicBean.setLat("25.1545");

        if (getIntent().hasExtra("rentId"))
        {
            //编辑进来的
            mPresenter.viewHouseRent(getIntent().getStringExtra("rentId"));
        }
        if (!TextUtils.isEmpty(housePublicBean.getLat()) && !TextUtils.isEmpty(housePublicBean.getLgt())) {
            housepublishpublishContenXxdzTxt.setFocusable(true);
        } else {
            housepublishpublishContenXxdzTxt.setFocusable(false);
        }
        if (getIntent().hasExtra("MyStoryBeanResultBean")) {
            selectResultBean = (MyStoryBean.ResultBean) getIntent().getSerializableExtra("MyStoryBeanResultBean");
            housepublishpublishContenGsdpTxt.setText(selectResultBean.getStoreName());
            //从店铺里跳转过来
        }
        toolbar.setBackgroundColor(ArmsUtils.getColor(this, R.color.color_EDEDED));
        housePayWayBean = (HousePayWayBean) getIntent().getSerializableExtra("HousePayWayBean");
        if (housePayWayBean.getCategory().equals("cw")||housePayWayBean.getCategory().equals("cfck"))
        {
            housepublishpublishContenFgrnjjLay.setVisibility(View.GONE);
            housepublishpublishContenZxLay.setVisibility(View.GONE);
        }
        if (housePayWayBean.getCategory().equals("bgs")) {
            housepublishpublishContenLxLay.setVisibility(View.VISIBLE);
        } else {
            housepublishpublishContenLxLay.setVisibility(View.GONE);
        }
        setmanButtonStatus(true);
        initGlide();

        UserBean userBean = DataHelper.getDeviceData(this, AppConstant.USER_INFO);
        if (userBean != null && userBean.getMobile() != null && userBean.getMobile().length() > 2) {
            MystoryAddStoryLxdh.setText(userBean.getMobile().substring(2, userBean.getMobile().length()));
            if (MystoryAddStoryLxdh.getText().toString().length() > 1 && "1".equals(MystoryAddStoryLxdh.getText().toString().substring(0, 1))) {
                MystoryAddStoryPhoneSsqyTxt.setText("+86");
            } else {
                MystoryAddStoryPhoneSsqyTxt.setText("+63");
            }
        }
        housePublisInfoEdit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s != null) {
                    housePublisInfoTxtNum.setText(s.length() + "/600");
                }
            }
        });


        //获取店铺
        mPresenter.querySelectStory();

    }

    @Override
    public void showLoading() {
        loadingDialog.show();
    }

    @Override
    public void hideLoading() {
        loadingDialog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void addHouseRentSuccess() {
        CustomPopupWindow customPopupWindow = AppUtil.showPopuWindow(this, CustomPopupWindow.inflateView(this, R.layout.custom_popuwindow_dialog), housepublishpublishContenSzqyTxt);
        View view = customPopupWindow.getContentView();
        TextView membercenter_popuwindow_dialog_txt1 = view.findViewById(R.id.membercenter_popuwindow_dialog_txt1);
        TextView membercenter_popuwindow_dialog_txt2 = view.findViewById(R.id.membercenter_popuwindow_dialog_txt2);
        membercenter_popuwindow_dialog_txt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                killMyself();
            }
        });
        membercenter_popuwindow_dialog_txt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("isGoToShow", 1);
                setResult(RESULT_OK, intent);
                killMyself();
            }
        });
    }

    @Override
    public void getHouseArea(List<HousePayWayBean> housePayWayBeans) {
        //所在区域
        this.houseArea = housePayWayBeans;
        new MultiSelectPopWindow1.Builder(this)
                .setConfirmListener(new MultiSelectPopWindow1.OnConfirmClickListener() {
                    @Override
                    public void onClick(MessageEvent messageEvent) {
//                        selectIndexQy = messageEvent.getIndex();
                        housepublishpublishContenSzqyTxt.setText(messageEvent.getRoom() + (messageEvent.getDrawing() != null ? messageEvent.getDrawing() : "") + (messageEvent.getToilet() != null ? messageEvent.getToilet() : ""));
                        selectArea = messageEvent.getRoomIndex() != -1 ? (messageEvent.getDrawingIndex() != -1 ? (messageEvent.getToiletIndex() != -1 ? housePayWayBeans.get(messageEvent.getRoomIndex()).getChildren().get(messageEvent.getDrawingIndex()).getChildren().get(messageEvent.getToiletIndex()) : housePayWayBeans.get(messageEvent.getRoomIndex()).getChildren().get(messageEvent.getDrawingIndex())) : housePayWayBeans.get(messageEvent.getRoomIndex())) : null;
                    }
                })
                .setDataArray(housePayWayBeans)
                .setCancel(ArmsUtils.getString(this, R.string.user_set_editinfo_cancel))
                .setTitle(ArmsUtils.getString(this, R.string.dilaog_titile_xzszqy_txt))
                .setConfirm(ArmsUtils.getString(this, R.string.sure_txt))
                .build()
                .show(housepublishpublishContenSzqyTxt);
    }

    @Override
    public void getHousePayWayBeanSuccess(List<HousePayWayBean> housePayWayBeans) {
        if (housePayWayBeans != null && !housePayWayBeans.isEmpty()) {
            if (Api.ROOM_COUNT.equals(housePayWayBeans.get(0).getValue()) || Api.DRAWING_COUNT.equals(housePayWayBeans.get(0).getValue()) ||
                    Api.TOILET_COUNT.equals(housePayWayBeans.get(0).getValue()) || Api.FLOOR.equals(housePayWayBeans.get(0).getValue()) || Api.TOTAL_FLOOR.equals(housePayWayBeans.get(0).getValue())) {
                if (Api.ROOM_COUNT.equals(housePayWayBeans.get(0).getValue())) {
//                    househx_s = housePayWayBeans;
                } else if (Api.DRAWING_COUNT.equals(housePayWayBeans.get(0).getValue())) {
//                    househx_t = housePayWayBeans;
                }

                return;
            }
            new MultiSelectPopWindow.Builder(this)
                    .setConfirmListener(new MultiSelectPopWindow.OnConfirmClickListener() {
                        @Override
                        public void onClick(MessageEvent messageEvent) {
                            switch (housePayWayBeans.get(0).getValue()) {
                                case Api.CASH_PLEDGE:
                                    //押金
                                    houseyj = housePayWayBeans;
                                    selectIndexYj = messageEvent.getSelectId();
                                    housepublishpublishContenYjTxt.setText(messageEvent.getSelectData());
                                    break;
                                case Api.DAY_RENT:
                                    //付款方式
                                    selectIndexZf =  messageEvent.getSelectId();
                                    mhousePayWayBeans = housePayWayBeans;
                                    housepublishpublishContenFkfsTxt.setText(messageEvent.getSelectData());
                                    break;
                                case Api.RENT_ROOM:
                                    //房屋类型
                                    selectIndexfwlx =  messageEvent.getSelectId();
                                    housezfwlx = housePayWayBeans;
                                    housepublishpublishContenFwlxTxt.setText(messageEvent.getSelectData());
                                    break;
                                case Api.DECORATION_TYPE:
                                    //装修
                                    selectIndexZX =  messageEvent.getSelectId();
                                    housezx = housePayWayBeans;
                                    housepublishpublishContenZxTxt.setText(messageEvent.getSelectData());
                                    break;


                                case Api.FLOOR_CW:
                                    //车位楼层
                                    mfloor = housePayWayBeans.get( messageEvent.getSelectId());
                                    housepublishpublishContenLcTxt.setText(messageEvent.getSelectData());
                                    break;
                            }
                        }
                    })
                    .setDataArray(mPresenter.getHousePayWay(housePayWayBeans))
                    .setCancel(ArmsUtils.getString(this, R.string.user_set_editinfo_cancel))
                    .setTitle(getDialogTitle(housePayWayBeans.get(0).getValue()))
                    .setConfirm(ArmsUtils.getString(this, R.string.sure_txt))
                    .build()
                    .show(housepublishpublishContenSzqyTxt);
        }
    }

    @Override
    public void querySelectStorySuccess(List<MyStoryBean.ResultBean> resultBeans) {
        mresultBeans = resultBeans;
        if (mresultBeans == null || mresultBeans.isEmpty() || mresultBeans.size() == 1) {
            housepublishpublishGsdpLay.setVisibility(View.GONE);

            if (mresultBeans != null && mresultBeans.size() == 1 && !getIntent().hasExtra("MyStoryBeanResultBean")) {
                housepublishpublishContenGsdpTxt.setText(mresultBeans.get(0).getStoreName());
                selectResultBean = mresultBeans.get(0);
            }
        } else {
            housepublishpublishGsdpLay.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public HousePublicBean getHousePublicBean() {
        return housePublicBean;
    }

    @Override
    public void getFloorTypeAndFloor(List<HousePayWayBean> floors) {
        mfloors = floors;
        mPresenter.selectHouseFloor(this, housepublishpublishContenLcTxt, new HousePublishOfficePublishPresenter.SelectLcCallback() {
            @Override
            public void callback(HousePayWayBean floor, HousePayWayBean toFloor, HousePayWayBean totalFloor) {
                mfloor = floor;
                mtoFloor = toFloor;
                mtotalFloor = totalFloor;
                String temLc = "";
                if (mfloor != null) {
                    temLc = mfloor.getName();
                }
                if (toFloor != null) {
                    temLc += ("-" + toFloor.getName());
                }
                if (totalFloor != null) {
                    temLc += (" " + totalFloor.getName());
                }
                lcTextView().setText(temLc);
            }
        });
    }

    @Override
    public TextView zjTextview() {
        return housepublishpublishContenZjTxt;
    }

    @Override
    public TextView lcTextView() {
        return housepublishpublishContenLcTxt;
    }

    @Override
    public void viewHouseRentSuccess(HouseRentListShowInfoBean houseRentListShowInfoBean) {

    }

    @Override
    public void updateHouseRentSuccess() {
           //编辑成功
    }

    @OnClick({R.id.housepublishpublish_conten_img,R.id.housepublishpublish_conten_gsdp_txt, R.id.housepublishpublish_conten_zj_txt, R.id.housepublishpublish_conten_camer_img, R.id.housepublishpublish_conten_yj_txt, R.id.housepublishpublish_conten_fkfs_txt, R.id.housepublishpublish_conten_zx_txt, R.id.housepublishpublish_conten_fwlx_txt, R.id.housepublishpublish_conten_xxdz_txt, R.id.housepublishpublish_conten_lc_txt, R.id.housepublishpublish_conten_szqy_txt, R.id.housepublishpublish_conten_man_txt, R.id.housepublishpublish_conten_woman_txt, R.id.HousePublishOfficePublish_sure_txt})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.housepublishpublish_conten_img:
                if(imgBeans==null||imgBeans.isEmpty()){
                    Intent intent5 = new Intent(this, HousePushUpdateImgActivity.class);
                    intent5.putExtra("type", "selectImg");
                    ArmsUtils.startActivityForResult(intent5, AppConstant.START_ACTIVITY_REQUEST_CODE);
                    return;
                }

                //修改封面图
                Intent intent3 = new Intent(this, HousePushUpdateImgActivity.class);
                if (imgBeans!=null)
                {
                    intent3.putExtra("imgs", (Serializable) imgBeans);
                }else {
                    intent3.putExtra("type", "selectImg");
                }
                ArmsUtils.startActivityForResult(intent3, AppConstant.START_ACTIVITY_REQUEST_CODE);
                break;
            case R.id.housepublishpublish_conten_camer_img:
                //选择图片
                Intent intent = new Intent(this, HousePushUpdateImgActivity.class);
                intent.putExtra("type", "selectImg");
                ArmsUtils.startActivityForResult(intent, AppConstant.START_ACTIVITY_REQUEST_CODE);
                break;
            case R.id.housepublishpublish_conten_gsdp_txt:
                MemberCenterUserInfoBean memberCenterUserInfoBean = DataHelper.getDeviceData(this, AppConstant.user_memberInfo);
                mPresenter.popuwindSelectStore(HousePublishOfficePublishActivity.this, housepublishpublishContenGsdpTxt, memberCenterUserInfoBean, mresultBeans, new HousePublishDuanZuPublishPresenter.SelectStoreCallback() {
                    @Override
                    public void callBack(MyStoryBean.ResultBean resultBean) {
                        housepublishpublishContenGsdpTxt.setText(resultBean.getStoreName());
                        selectResultBean = resultBean;
                    }
                });
                break;
            case R.id.housepublishpublish_conten_zj_txt:
                mPresenter.selectZj(HousePublishOfficePublishActivity.this, housepublishpublishContenZjTxt);
                break;
            case R.id.housepublishpublish_conten_yj_txt:
                //押金
                mPresenter.getHousePayWayBean(Api.CASH_PLEDGE, "", houseyj);
                break;
            case R.id.housepublishpublish_conten_fkfs_txt:
                //付款方式
                mPresenter.getHousePayWayBean(Api.DAY_RENT, housePayWayBean.getCategory(), mhousePayWayBeans);
                break;
            case R.id.housepublishpublish_conten_zx_txt:
                //装修
                mPresenter.getHousePayWayBean(Api.DECORATION_TYPE, "", housezx);
                break;
            case R.id.housepublishpublish_conten_fwlx_txt:
                //房屋类型
                mPresenter.getHousePayWayBean(Api.RENT_ROOM, housePayWayBean.getCategory(), housezfwlx);
                break;
            case R.id.housepublishpublish_conten_xxdz_txt:
                //详细地址
                if (houseArea == null || houseArea.size() < 1) {
                    showMessage("请先选择所在区域");
                    return;
                }
                //具体地址
                Intent intentMap = new Intent(this, MapSelectAddressActivity.class);
                intentMap.putExtra("selectedAreaName", housepublishpublishContenSzqyTxt.getText().toString());
                intentMap.putExtra("lat",selectArea.getLat());
                intentMap.putExtra("lng",selectArea.getLgt());
                startActivityForResult(intentMap, 1004);
                break;
            case R.id.housepublishpublish_conten_lc_txt:
                //选择楼层
                if ("cw".equals(housePayWayBean.getCategory())) {
                    //车位的时候楼层要单独处理
                    mPresenter.getHousePayWayBean(Api.FLOOR_CW, "", mfloors);
                    return;
                }
                mPresenter.getFloorTypeAndFloor(mfloors);
                break;
            case R.id.housepublishpublish_conten_szqy_txt:
                //所在区域
                mPresenter.getAreaTree(Api.HOUSE_AREA, houseArea);
                break;

            case R.id.housepublishpublish_conten_man_txt:
                sex = "男";
                setmanButtonStatus(true);
                break;
            case R.id.housepublishpublish_conten_woman_txt:
                sex = "女";
                setmanButtonStatus(false);
                break;
            case R.id.HousePublishOfficePublish_sure_txt:
                //提交
                if (imgBeans == null || imgBeans.isEmpty()) {
                    showMessage("请选择图片");
                    return;
                }

                if (getIntent().getStringExtra("type").equals("bgs")) {
                    if (StringUtils.ViewisEnpty(housepublishpublishContenFwlxTxt)) {
                        showMessage("请选择房屋类型");
                        return;
                    }
                }
                if (TextUtils.isEmpty(MystoryAddStoryLxdh.getText().toString()) || MystoryAddStoryLxdh.getText().toString().length() < 10) {
                    showMessage("请输入联系电话");
                    return;
                }
                if (MystoryAddStoryPhoneSsqyTxt.getText().toString().equals("+63")) {
                    if (MystoryAddStoryLxdh.getText().toString().substring(0, 1).equals("0")) {
                        showMessage("手机号不能是0开头");
                        return;
                    }
                    if (!MystoryAddStoryLxdh.getText().toString().substring(0, 1).equals("9")) {
                        showMessage("手机号必须是9开头");
                        return;
                    }
                    if (MystoryAddStoryLxdh.getText().toString().length() != 10) {
                        showMessage("手机号长度必须是十位");
                        return;
                    }
                } else {
                    if (MystoryAddStoryLxdh.getText().toString().length() != 11) {
                        showMessage("手机号必须是11位");
                        return;
                    }
                    if (!MystoryAddStoryLxdh.getText().toString().substring(0, 1).equals("1")) {
                        showMessage("手机号格式有误");
                        return;
                    }
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenBtTxt)) {
                    showMessage("请输入标题");
                    return;
                }

                if (StringUtils.ViewisEnpty(housepublishpublishContenSzqyTxt) || houseArea == null) {
                    showMessage("请选择所在区域");
                    return;
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenXxdzTxt)) {
                    showMessage("请选择具体地址");
                    return;
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenMjTxt)) {
                    showMessage("请输入面积");
                    return;
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenLcTxt)) {
                    showMessage("请选择楼层");
                    return;
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenYjTxt)) {
                    showMessage("请选择押金");
                    return;
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenLxrTxt)) {
                    showMessage("请输入联系人");
                    return;
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenLcTxt)) {
                    showMessage("请选择楼层");
                    return;
                }

                //详细地址从地图选择，先填写一个默认的
                housePublicBean.setRentType(housePayWayBean.getCategory());
                //房屋类型
                if (housezfwlx != null) {
                    housePublicBean.setRentRoom(housezfwlx.get(selectIndexfwlx).getDictId());
                }

                //付款方式
                if (StringUtils.ViewisEnpty(housepublishpublishContenFkfsTitleTxt)) {
                    showMessage("请选择付款方式");
                    return;
                }
                if (mfloor != null && mtoFloor != null) {
                    if (Integer.parseInt(mfloor.getAliasName()) > Integer.parseInt(mtoFloor.getAliasName())) {
                        showMessage("请选择合理的楼层区间");
                        return;
                    }
                }
                if (mtotalFloor == null && mtoFloor == null && mfloor == null) {
                    showMessage("请选择楼层");
                    return;
                }
                if (mtotalFloor != null && mtoFloor != null) {
                    if (Integer.parseInt(mtoFloor.getAliasName()) > Integer.parseInt(mtotalFloor.getAliasName())) {
                        showMessage("当前楼层不能大于总楼层,请重新选择");
                        return;
                    }
                }
                if (mfloor != null && mtotalFloor != null) {
                    if (Integer.parseInt(mfloor.getAliasName()) > Integer.parseInt(mtotalFloor.getAliasName())) {
                        showMessage("当前楼层不能大于总楼层,请重新选择");
                        return;
                    }
                }
                if (mresultBeans != null && !mresultBeans.isEmpty()) {
                    if (selectResultBean == null) {
                        showMessage("请选择所属店铺");
                        return;
                    }
                    housePublicBean.setUserStoreId(selectResultBean.getStoreId());
                }
                if (StringUtils.ViewisEnpty(housepublishpublishContenZjTxt)) {
                    showMessage("请输入租金");
                    return;
                }

                housePublicBean.setHouseName(housepublishpublishContenBtTxt.getText().toString().trim());

                //区域houseArea
                housePublicBean.setHouseArea(selectArea.getDictId());
                housePublicBean.setAcreage(housepublishpublishContenMjTxt.getText().toString().trim());
                if (mfloor != null) {
                    housePublicBean.setFloor(mfloor.getDictId());
                }
                if (mtoFloor != null) {
                    housePublicBean.setToFloor(mtoFloor.getDictId());
                }
                if (mtotalFloor != null) {
                    housePublicBean.setTotalFloor(mtotalFloor.getDictId());
                }


                //付款方式
                housePublicBean.setDayRent(mhousePayWayBeans.get(selectIndexZf).getDictId());
                 if (!housePayWayBean.getCategory().equals("cfck")&&!housePayWayBean.getCategory().equals("cw")&&StringUtils.ViewisEnpty(housepublishpublishContenKrngwTxt)) {
                    showMessage("请输入可容纳的工位");
                    return;
                }
                 if (!"cw".equals(housePayWayBean.getCategory()))
                 {
                     if (housepublishpublishContenZxTxt.getText().toString().trim().length() < 1) {
                         showMessage("请选择房屋装修");
                         return;
                     }
                 }


                if (housePublicBean.getLat()==null||housePublicBean.getLgt()==null||TextUtils.isEmpty(housePublicBean.getLgt())||TextUtils.isEmpty(housePublicBean.getLat()))
                {
                    showMessage("未获取到经纬度，请重新选择地址");
                    return;
                }
                housePublicBean.setAccommodationStation(housepublishpublishContenKrngwTxt.getText().toString());
                housePublicBean.setWechatNumber(housepublishpublishContenWxhTxt.getText().toString().trim());
                if (selectIndexZX>-1)
                {
                    housePublicBean.setDecorationType(housezx.get(selectIndexZX).getDictId());
                }
                housePublicBean.setCashPledge(houseyj.get(selectIndexYj).getDictId());
                housePublicBean.setLandlord(housepublishpublishContenLxrTxt.getText().toString().trim());
                housePublicBean.setLandlordGender(sex);
                housePublicBean.setLandlordMobile(MystoryAddStoryPhoneSsqyTxt.getText().toString().replace("+", "").trim() + MystoryAddStoryLxdh.getText().toString());

                housePublicBean.setIsSeparable(switchButtonSfkfg.isChecked() ? "1" : "0");//是否可分割
                housePublicBean.setIsOfficeAppliances(switchButtonSfdbgjj.isChecked() ? "1" : "0");//办公用具
                housePublicBean.setHouseImage(imgBeans);
                housePublicBean.setDetail(housePublisInfoEdit.getText().toString());
                mPresenter.addHouseRent(AppUtil.entityToMap(housePublicBean));
                break;
        }
    }

    /**
     * 性别控制
     *
     * @param firstIsSelect
     */
    public void setmanButtonStatus(boolean firstIsSelect) {
        if (firstIsSelect) {
            //选中先生
            housepublishpublishContenManTxt.setBackgroundResource(R.drawable.halfleftbutton_yellow_bg);
            housepublishpublishContenManTxt.setTextColor(ArmsUtils.getColor(this, R.color.color_191919));
            housepublishpublishContenWomanTxt.setBackgroundResource(R.drawable.halfrightbutton_gray_bg);
            housepublishpublishContenWomanTxt.setTextColor(ArmsUtils.getColor(this, R.color.white));
        } else {
            //选中女士
            housepublishpublishContenManTxt.setBackgroundResource(R.drawable.halfleftbutton_gray_bg);
            housepublishpublishContenManTxt.setTextColor(ArmsUtils.getColor(this, R.color.white));
            housepublishpublishContenWomanTxt.setBackgroundResource(R.drawable.halfrightbutton_yellow_bg);
            housepublishpublishContenWomanTxt.setTextColor(ArmsUtils.getColor(this, R.color.color_191919));
        }
    }

    /**
     * 根据类型动态设置标题
     *
     * @param value
     * @return
     */
    public String getDialogTitle(String value) {
        String temTitle = "";
        switch (value) {
            case Api.CASH_PLEDGE:
                //押金
                temTitle = ArmsUtils.getString(this, R.string.housepublishpublish_info_title_yj);
                break;
            case Api.DAY_RENT:
                //付款方式
                temTitle = ArmsUtils.getString(this, R.string.housepublishpublish_title_fkfs);
                break;
            case Api.RENT_ROOM:
                //合租房间类型
                temTitle = ArmsUtils.getString(this, R.string.housepublishpublish_title_fwlx);
                break;
            case Api.LANDLORD_TYPE:
                //您的身份
                temTitle = ArmsUtils.getString(this, R.string.housepublishpublish_title_ndsf);
                break;
            case Api.FLOOR:
                //楼层
                temTitle = ArmsUtils.getString(this, R.string.housepublishpublish_title_lc);
                break;
            case Api.DECORATION_TYPE:
                //楼层
                temTitle = ArmsUtils.getString(this, R.string.housepublishpublish_title_qxzfwzx);
                break;

            case Api.FLOOR_CW:
                temTitle = ArmsUtils.getString(this, "housepublishpublish_title_cwlc");
                break;
        }
        return temTitle;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null && resultCode == RESULT_OK) {
            if (requestCode == AppConstant.START_ACTIVITY_REQUEST_CODE) {
                //选择图片回来
                housepublishpublishContenNoImgLay.setVisibility(View.GONE);
                imgBeans = (List<ImgBean>) data.getSerializableExtra("imgs");
                if (imgBeans != null && !imgBeans.isEmpty()) {
                    housepublishpublishContenImg.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mglideImage.loadImage(HousePublishOfficePublishActivity.this, ImageConfigImpl.builder().url(imgBeans.get(0).getImageUrl()).imageRadius(5)
                                    .imageView(housepublishpublishContenImg)
                                    .build());
                        }
                    }, 500);


                }
            }
            if (requestCode == 1004 && resultCode == RESULT_OK && data != null) {
                //选择地址返回
                if (!data.hasExtra("SelectAddressMapBean")) {
                    showMessage("选取地址异常");
                    return;
                }
                housepublishpublishContenXxdzTxt.setFocusableInTouchMode(true);
                housepublishpublishContenXxdzTxt.setFocusable(true);
                housepublishpublishContenXxdzTxt.requestFocus();
                SelectAddressMapBean selectAddressMapBean = (SelectAddressMapBean) data.getSerializableExtra("SelectAddressMapBean");
                housepublishpublishContenXxdzTxt.setText(selectAddressMapBean.getDetileAddress());
                housePublicBean.setAddressDetail(selectAddressMapBean.getDetileAddress());
                housePublicBean.setLgt(selectAddressMapBean.getLgt());
                housePublicBean.setLat(selectAddressMapBean.getLat());
            }
        }
    }
}
